<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>忘记密码 - 名片管理系统</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <style>
    body {
      background-color: #f8f9fa;
    }
    .forgot-password-container {
      max-width: 400px;
      margin: 100px auto;
      padding: 20px;
      background-color: white;
      border-radius: 10px;
      box-shadow: 0 0 10px rgba(0,0,0,0.1);
    }
    .error-message {
      color: #dc3545;
      margin-top: 10px;
      display: none;
    }
    .success-message {
      color: #198754;
      margin-top: 10px;
      display: none;
    }
  </style>
</head>

<body>
  <div class="container">
    <div class="forgot-password-container">
      <h2 class="text-center mb-4">忘记密码</h2>
      <form id="forgotPasswordForm">
        <div class="mb-3">
          <label for="email" class="form-label">邮箱</label>
          <input type="email" class="form-control" id="email" required>
        </div>
        <div class="d-grid gap-2">
          <button type="submit" class="btn btn-primary">发送重置链接</button>
        </div>
        <div class="text-center mt-3">
          <a href="login.html">返回登录</a>
        </div>
        <div id="errorMessage" class="error-message text-center"></div>
        <div id="successMessage" class="success-message text-center"></div>
      </form>
    </div>
  </div>

  <script src="js/api.js"></script>
  <script>
    document.getElementById('forgotPasswordForm').addEventListener('submit', async (e) => {
      e.preventDefault();
      
      const email = document.getElementById('email').value;
      const errorMessage = document.getElementById('errorMessage');
      const successMessage = document.getElementById('successMessage');
      
      try {
        await api.auth.forgotPassword(email);
        successMessage.textContent = '重置密码链接已发送到您的邮箱，请查收';
        successMessage.style.display = 'block';
        errorMessage.style.display = 'none';
      } catch (error) {
        errorMessage.textContent = error.message;
        errorMessage.style.display = 'block';
        successMessage.style.display = 'none';
      }
    });
  </script>
</body>

</html>